import { Component, Vue, Inject } from 'vue-property-decorator';

import { IUserContentPraise } from '@/shared/model/user-content-praise.model';
import UserContentPraiseService from './user-content-praise.service';

@Component
export default class UserContentPraiseDetails extends Vue {
  @Inject('userContentPraiseService') private userContentPraiseService: () => UserContentPraiseService;
  public userContentPraise: IUserContentPraise = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.userContentPraiseId) {
        vm.retrieveUserContentPraise(to.params.userContentPraiseId);
      }
    });
  }

  public retrieveUserContentPraise(userContentPraiseId) {
    this.userContentPraiseService()
      .find(userContentPraiseId)
      .then(res => {
        this.userContentPraise = res;
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
